package com.example.myapplication.view;

import android.content.Context;
import android.graphics.Color;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.myapplication.R;

/**
 * @author: rongfeng
 * @date: 2021/6/10
 * @description
 */
public class FansCardView extends FrameLayout {
    private View mView;
    private LinearLayout ll_bg;
    private TextView tv_name, tv_level;
    private FrameLayout fl_right_bg;
    private ImageView img_border, img_icon;
    int bg_resId, tv_name_shadowColor, right_bg_resId, tv_level_shadowColor, img_border_resId, img_icon_resId;

    public FansCardView(@NonNull Context context) {
        super(context);
        initView(context);
    }

    public FansCardView(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        initView(context);
    }

    private void initView(Context context){
        mView = LayoutInflater.from(context).inflate(R.layout.view_fans_card, this);
        ll_bg = mView.findViewById(R.id.ll_bg);
        tv_name = mView.findViewById(R.id.tv_name);
        tv_level = mView.findViewById(R.id.tv_level);
        fl_right_bg = mView.findViewById(R.id.fl_right_bg);
        img_border = mView.findViewById(R.id.img_border);
        img_icon = mView.findViewById(R.id.img_icon);
    }


    public void setData(int type) {
        initModel(type);
    }

    private void initModel(int type) {
        if (type == 1) {
            bg_resId = R.drawable.shape_guardian_nameplate01;
            tv_name_shadowColor = Color.parseColor("#ffff005a");
            right_bg_resId = R.drawable.shape_guardian_nameplate01_right;
            tv_level_shadowColor = Color.parseColor("#fffc14ac");
            img_border_resId = R.drawable.shape_guardian_nameplate01_border;
            img_icon_resId = R.mipmap.guardian_nameplate01_icon;
        } else if (type == 2) {
            bg_resId = R.drawable.shape_guardian_nameplate02;
            tv_name_shadowColor = Color.parseColor("#ffff5300");
            right_bg_resId = R.drawable.shape_guardian_nameplate02_right;
            tv_level_shadowColor = Color.parseColor("#ffff4e00");
            img_border_resId = R.drawable.shape_guardian_nameplate02_border;
            img_icon_resId = R.mipmap.guardian_nameplate02_icon;
        } else if (type == 3) {
            bg_resId = R.drawable.shape_guardian_nameplate03;
            tv_name_shadowColor = Color.parseColor("#ffbd00ff");
            right_bg_resId = R.drawable.shape_guardian_nameplate03_right;
            tv_level_shadowColor = Color.parseColor("#ffff4e00");
            img_border_resId = R.drawable.shape_guardian_nameplate03_border;
            img_icon_resId = R.mipmap.guardian_nameplate03_icon;
        }
        ll_bg.setBackgroundResource(bg_resId);
        fl_right_bg.setBackgroundResource(right_bg_resId);
        tv_name.setShadowLayer(6f, 0, 0, tv_name_shadowColor);
        tv_level.setShadowLayer(6f, 0, 0, tv_level_shadowColor);
        img_border.setBackgroundResource(img_border_resId);
        img_icon.setImageResource(img_icon_resId);
    }

}
